{include file="public/_meta" /}
<body>
<style>
    .required_b{
        color: red;
    }
</style>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">线索成本导入</h4>
                                    <div class="layui-btn-container" style="margin-left: 65%">
                                        <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                                        <button type="button" class="layui-btn" id="test9">导入</button>
                                    </div>
                                    <button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#addRowModal" onClick="add_item(0)">
                                        <i class="fa fa-plus"></i>
                                        添加
                                    </button>

                                    <button type="button" class="layui-btn layui-btn-danger layui-btn-radius" onClick="del()">删除</button>

                                </div>

                                <form class="row" id="selectform">

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="acc_name" value="{$acc_name}" placeholder="账户名称">
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="adv_id" value="{$adv_id}" placeholder="账户ID">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="type" id="type">
                                                <option value="0">列表明细</option>
                                                <option value="1">账户统计</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="channel_id[]" id="channel_id" multiple="multiple">
                                                <option value="0">全部渠道</option>
                                                {volist name="channels" id="vo"}
                                                <option value="{$key}">{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="pro_id" id="pro_id">
                                                <option value="">全部产品</option>
                                                {volist name="products" id="vo"}
                                                <option value="{$key}">{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="cityname" value="{$cityname}" placeholder="请输入城市">
                                        </div>
                                    </div>


<!--                                    <div class="col-md-6 col-lg-2">-->
<!--                                        <div class="form-group">-->

<!--                                            <select class="form-control input-full" name="sprovince" id="sprovince" onchange="loadRegion('sprovince',2,'scity')">-->
<!--                                                <option value="0">省份/直辖市</option>-->
<!--                                                {volist name="province" id="vo"}-->
<!--                                                <option value="{$vo.id}" >{$vo.name}</option>-->
<!--                                                {/volist}-->
<!--                                            </select>-->
<!--                                        </div>-->
<!--                                    </div>-->
<!--                                    <div class="col-md-6 col-lg-2">-->
<!--                                        <div class="form-group">-->

<!--                                            <select class="form-control input-full" name="scity" id="scity">-->
<!--                                                <option value="0">市/县</option>-->
<!--                                            </select>-->
<!--                                        </div>-->
<!--                                    </div>-->

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="orderb" id="orderb">
                                                <option value="0">排序</option>
                                                <option value="1" {if condition="$orderb eq 1"}selected{/if}>展示量升序</option>
                                                <option value="2" {if condition="$orderb eq 2"}selected{/if}>展示量降序</option>
                                                <option value="3" {if condition="$orderb eq 3"}selected{/if}>点击量升序</option>
                                                <option value="4" {if condition="$orderb eq 4"}selected{/if}>点击量降序</option>
                                                <option value="5" {if condition="$orderb eq 5"}selected{/if}>消耗金额升序</option>
                                                <option value="6" {if condition="$orderb eq 6"}selected{/if}>消耗金额降序</option>
                                                <option value="7" {if condition="$orderb eq 7"}selected{/if}>转化量升序</option>
                                                <option value="8" {if condition="$orderb eq 8"}selected{/if}>转化量降序</option>
                                                <option value="9" {if condition="$orderb eq 9"}selected{/if}>进线量升序</option>
                                                <option value="10" {if condition="$orderb eq 10"}selected{/if}>进线量降序</option>
                                                <option value="11" {if condition="$orderb eq 11"}selected{/if}>转化成本升序</option>
                                                <option value="12" {if condition="$orderb eq 12"}selected{/if}>转化成本降序</option>
                                                <option value="13" {if condition="$orderb eq 13"}selected{/if}>真实转化成本升序</option>
                                                <option value="14" {if condition="$orderb eq 14"}selected{/if}>真实转化成本降序</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="times" id="times" value="{$times}" placeholder="日期" autocomplete="off">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="is_kong" id="is_kong">
                                                <option value="">是否空耗</option>
                                                <option value="1">账户转化0空耗</option>
                                                <option value="2">纯空耗</option>
                                                <option value="3">进线0空耗</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="youhua_id" id="youhua_id">
                                                <option value="">全部优化师</option>
                                                {volist name="youhua" id="vo"}
                                                <option value="{$vo.uid}">{$vo.realname}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <button type="submit" class="btn btn-primary">查询</button>
                                            <a href="{:url('stat/clueCost')}" class="btn btn-info" style="color: white;position: absolute;left: 100px;">重置</a>
                                            <div class="btn btn-primary" onclick="recostprice()" style="color: white;position: absolute;left: 200px;">刷新成本</div>
                                        </div>
                                    </div>

                                </form>

                            </div>
                            <div class="layui-card-body">

                                <blockquote class="layui-elem-quote layui-quote-nm">
                                    <span style="margin-right: 50px;">展示数量：{$exposure_val}</span><span style="margin-right: 50px;">点击数量：{$click_val}</span><span style="margin-right: 50px;">账户消耗：{$all_money}</span><span style="margin-right: 50px;">真实消耗：{$true_consume}</span><span style="margin-right: 50px;">账户转化量：{$transform_val}</span><span style="margin-right: 50px;">Api进线量：{$clue_num}</span>
                                    <span style="margin-right: 50px;">点击率：{$dianji_rate}%</span><span style="margin-right: 50px;">转化率：{$change_rate}%</span><span style="margin-right: 50px;">账户成本：{$avgChangeMoney}</span><span style="margin-right: 50px;">真实成本：{$avgConsume}</span>

                                </blockquote>
                            </div>


                            <div class="card-body">
                                <!-- Modal -->
                                <div class="modal fade" id="addRowModal" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">添加</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="province" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">筛选渠道<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="channel" id="channel" onchange="loadRule('channel','account')">
                                                                    <option value="0">--请选择--</option>
                                                                    {volist name="channels" id="vo"}
                                                                    <option value="{$key}">{$vo}</option>
                                                                    {/volist}
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="province" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">筛选产品<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="pro_id" id="pro_id2" >
                                                                    <option value="0">--请选择--</option>
                                                                    {volist name="products" id="vo"}
                                                                    <option value="{$key}">{$vo}</option>
                                                                    {/volist}
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="province" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">选择账号<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="account" id="account">
                                                                    <option value="0">--请选择--</option>
                                                                </select>
                                                            </div>
                                                        </div>



                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="dtime" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">选择日期 <b class="required_b">*</b> </font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="dtime" name="dtime" placeholder="选择日期">
                                                            </div>
                                                        </div>


                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="province" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">省份/直辖市<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="province" id="province" onchange="loadRegion('province',2,'city')">
                                                                    <option value="0">省份/直辖市</option>
                                                                    {volist name="province" id="vo"}
                                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                                    {/volist}
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="city" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">市/县<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="city" id="city" onchange="loadRegion('city',3,'town')">
                                                                    <option value="0">市/县</option>
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="exposure_val" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">展示数量<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="exposure_val" name="exposure_val" placeholder="展示数量">
                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="click_val" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">点击数量<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="click_val" name="click_val" placeholder="点击数量">
                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="money" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">账户消耗<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="money" name="money" placeholder="账户消耗">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="money" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">真实消耗<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="true_consume" name="true_consume" placeholder=真实消耗">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="transform_val" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">账户转化量<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="transform_val" name="transform_val" placeholder="账户转化量">
                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="transform_val" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">Api进线量<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="clue_num" name="clue_num" placeholder="Api进线量">
                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="transform_val" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">账户成本<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="change_cost" name="change_cost" placeholder="账户成本">
                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="transform_val" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">真实成本<b class="required_b">*</b></font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="true_cost" name="true_cost" placeholder="真实成本">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="remark" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">备注</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <textarea id="remark" name="remark" class="form-control input-full" style=""></textarea>
                                                            </div>
                                                        </div>

                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <input type="hidden" id="id" name="id" value="">
                                                        <button type="submit" id="addRowButton" class="btn btn-primary">保存</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>


                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>
                                            {if $type!=1}
                                            <th>ID</th>
                                            {/if}
                                            <th>渠道</th>
                                            <th>产品</th>
                                            <th>账户信息</th>
                                            {if $type!=1}
                                            <th>日期</th>
                                            <th>城市</th>
                                            {/if}
                                            <th>展示数量</th>
                                            <th>点击数量</th>
                                            <th>账户消耗</th>
                                            <th>真实消耗 </th>
                                            <th>账户转化量</th>
                                            <th>Api进线量</th>
                                            <th>账户成本</th>
                                            <th>真实成本</th>
                                            {if $type!=1}
                                            <th>创建时间</th>
                                            <th style="width: 10%">操作</th>
                                            {/if}
                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="infos" id="vo"}
                                        <tr>
                                            {if $type!=1}
                                            <td>{$vo.id}</td>
                                            {/if}
                                            <td>{$vo.channel_name}</td>
                                            <td>{$vo.pro_name}</td>
                                            <td>
                                                账户ID：{$vo.adv_id}<br>
                                                名称：{$vo.acc_name}<br>
                                                简称：{$vo.acc_desc}
                                            </td>
                                            {if $type!=1}
                                            <td>
                                               {$vo.time}
                                            </td>
                                            <td>
                                                {$vo.city}
                                            </td>
                                            {/if}
                                            <td>
                                                {$vo.exposure_val}
                                            </td>
                                            <td>
                                                {$vo.click_val}
                                            </td>
                                            <td>
                                                {$vo.money}
                                            </td>
                                            <td>
                                                {$vo.true_consume}
                                            </td>
                                            <td>
                                                {$vo.transform_val}
                                            </td>
                                            <td>
                                                {$vo.clue_num}
                                            </td>
                                            <td>
                                                {$vo.change_cost}
                                            </td>
                                            <td>
                                                {$vo.true_cost}
                                            </td>
                                            {if $type!=1}
                                            <td>{$vo.create_time}
                                            </td>

                                            <td>
                                                <div class="form-button-action">



                                                    <button type="button" title="编辑" class="btn btn-link btn-primary btn-lg" data-toggle="modal" data-target="#addRowModal" onClick="edit_item('{$vo.id}')">
                                                        <i class="fa fa-edit"></i>编辑
                                                    </button>

                                                    <button type="button" data-toggle="tooltip" onClick="admin_del(this,'{$vo.id}')" title="" class="btn btn-link btn-danger" data-original-title="删除">
                                                        <i class="fa fa-times"></i>删除
                                                    </button>

                                                </div>



                                            </td>
                                            {/if}
                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>

                                    <!-- 分页 (调取通用方法)-->
                                     <div class="layui-box layui-laypage layui-laypage-molv">{:pagination($infos)}</div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'status_url':"{:url('clue/status')}",
        'delete_url':"{:url('clue/delete')}",
        'item_url':"{:url('clue/edit')}",
        'item_url2':"{:url('clue/edit2')}",
        'add_url':"{:url('clue/save')}",
        'clue_url':"{:url('clue/clue_url')}",
        'city_url':"{:url('clue/getRegion')}",
        'push_rule':"{:url('clue/getMerchantPush')}",
        'push_url':"{:url('clue/findPush')}",
        'get_account':"{:url('stat/getAccount')}",
        'saveclue':"{:url('stat/saveClueCost')}",
        'editclue':"{:url('stat/editClueCost')}",
        'del_clue':"{:url('stat/delClueCost')}",
        'improtexcel':"{:url('stat/importClueCost')}",
    };


    function recostprice(){
        var times=$('#times').val();
        layer.confirm('确认要刷新成本吗？',function(index){
            var loading = layer.load('加载中...', {
                shade: [0.3,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                type: 'POST',
                url: "{:url('Stat/reCostPriceQueue')}",
                dataType: 'json',
                data: {times:times},
                success: function(data){
                    layer.close(loading);
                    if(data.code == 1001){
                        layer.msg(data.msg,{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }


    function loadRule(sel,selName){
        $("#"+selName+" option").each(function(){
            $(this).remove();
        });
        $("<option value=0>请选择</option>").appendTo($("#"+selName));
        if($("#"+sel).val()==0){
            return;
        }
        $.post(SCOPE.get_account,{pid:$("#"+sel).val()},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(k,v) {
                        $("<option value='"+v.id+"'>【"+v.acc_name+"】【账号ID"+v.adv_id+"】</option>").appendTo($("#"+selName));
                    });
                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#"+selName));
                }
            }
        );
    }

    function loadRegion(sel,type_id,selName){
        $("#"+selName+" option").each(function(){
            $(this).remove();
        });
        $("<option value=0>请选择</option>").appendTo($("#"+selName));
        if($("#"+sel).val()==0){
            return;
        }
        $.post(SCOPE.city_url,{pid:$("#"+sel).val(),type:type_id},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(idx,item){
                        $("<option value="+item.id+">"+item.name+"</option>").appendTo($("#"+selName));
                    });
                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#"+selName));
                }
            }
        );
    }

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({
            rules:{
                clue_name:{
                    required:true,
                    maxlength:30
                },
                phone:{
                    required:true,
                    number:true,
                    minlength:11,
                    maxlength:11
                },
                age:{
                    number:true
                },
                email:{
                    email:true,
                    maxlength:100
                },
                wx_id:{
                    maxlength:30
                },
                qq:{
                    maxlength:30
                },
                remark:{
                    maxlength:300
                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.saveclue;
                if(commitStatus==true){
                    return false;
                }
                var province = $("#province").val();
                var city = $("#city").val();
                if(province != 0 && city == 0){
                    layer.msg('请选择市/县',{icon:2,time:2000});
                    return false;
                }
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function del(){
        //询问框

        layer.confirm('确定要删除当前查询的数据？', {
            btn: ['确认','取消'] //按钮
        }, function(){

            /*表单提交*/
            $("#selectform").ajaxSubmit({
                type: 'post',
                url: "{:url('stat/delClueCostAll')}",
                success: function(data){
                    if(data.code == 1001){
                        commitStatus = true;
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        }, function(){
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }
                },
                error: function(XmlHttpRequest, textStatus, errorThrown){
                    layer.msg(errorThrown,{icon:2,time:2000});
                }
            });

        }, function(){

        });
    }

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal2").validate({

            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.push_url;
                if(commitStatus==true){
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function add_item(id) {
        $("input[name='id']").val(id);
        document.getElementById('form-modal').reset();
        $("#city").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#city"));
        $(".fw-mediumbold").text('添加');
    }

    function edit_item(id) {
        $("#city").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#city"));
        $.ajax({
            type: 'GET',
            url: SCOPE.editclue,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('编辑');
                    $("#id").val(res.data.id);

                    $("#channel").find("option[value="+res.data.channel_id+"]").attr("selected",true);
                    $("#account").children().remove();
                    $("<option value='"+res.data.acc_id+"'>【"+res.data.acc_name+"】【账号ID"+res.data.adv_id+"】</option>").appendTo($("#account"));
                    $("#dtime").val(res.data.time);
                    $("#exposure_val").val(res.data.exposure_val);
                    $("#click_val").val(res.data.click_val);
                    $("#money").val(res.data.money);
                    $("#transform_val").val(res.data.transform_val);
                    $("#clue_num").val(res.data.clue_num);
                    $("#change_cost").val(res.data.change_cost);
                    $("#true_cost").val(res.data.true_cost);
                    $("#true_consume").val(res.data.true_consume);
                    $("#remark").val(res.data.remark);
                    $("#province").val(res.data.prov);
                    $("#pro_id2").val(res.data.pro_id);
                    if(res.data.city != ''){
                        $("#city").children().remove();
                        $("<option value='"+res.data.city+"'>"+res.data.city_name+"</option>").appendTo($("#city"));
                    }
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }

    function edit_item2(id,city) {
        $("#mrule").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#mrule"));
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url2,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('推送');
                    $("#id2").val(res.data.id);
                    $("#clue_name2").val(res.data.clue_name);
                    $("#phone2").val(res.data.phone);

                    $("#remark2").val(res.data.remark);
                    $("#city2").text(city);

                    $("#merchant").children().remove();


                    $.each(res.data.merchant,function(k,v) {
                        $("<option value='"+v.id+"'>【"+v.mer_name+"】【账号"+v.username+"】(联系电话"+v.phone+")</option>").appendTo($("#merchant"));
                    });

                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }



    /*删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.del_clue,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        $(obj).parents("tr").remove();
                        layer.msg(data.msg,{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }


    /*机构-停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要禁止推送吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.status_url;
            $.post(url,{status:2,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('已禁止推送!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });


        });
    }

    /*机构-启用*/
    function admin_start(obj,id){
        layer.confirm('确认要推送线索吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            var url = SCOPE.status_url;
            $.post(url,{status:1,id:id},function(data){
                if(data.code == 1001){

                    layer.msg('已推送!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            });
        });
    }

    laydate.render({
        elem: '#times'
        ,type: 'date'
        ,range: true
    });

    //自定义格式
    laydate.render({
        elem: '#dtime'
        ,format: 'yyyy-MM-dd'
    });

    $('#sprovince').val('{$sprovince}')
    $('#pro_id').val('{$pro_id}')
    $('#type').val('{$type}')
    $('#is_kong').val('{$is_kong}');
    $('#youhua_id').val('{$youhua_id}');
    // $('#sprovince').find('option[value="{$sprovince}"]').attr('selected',true);
    // $('#pro_id').find('option[value="{$pro_id}"]').attr('selected',true);

    var sprovinceid=$('#sprovince').val();
    if(sprovinceid>0){
        $.post(SCOPE.city_url,{pid:sprovinceid,type:2},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(idx,item){
                        $("<option value="+item.id+">"+item.name+"</option>").appendTo($("#scity"));
                    });

                    // $('#scity').find('option[value="{$scity}"]').attr('selected',true);
                    $('#scity').val('{$scity}');

                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#scity"));
                }
            }
        );
    }




</script>
<script src="__STATIC__/layui/layui.js"></script>
<script>
    layui.use(['upload', 'element', 'layer'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;

        //选完文件后不自动上传
        upload.render({
            elem: '#test8'
            ,url: "{:url('stat/importClueCost')}" //此处配置你自己的上传接口即可
            ,auto: false
            //,multiple: true
            ,accept:'file'
            ,bindAction: '#test9'
            ,done: function(res){
                if(res.code == 1001){
                    layer.msg(res.msg,{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{

                    layer.alert(res.msg, {

                        closeBtn: 0
                        ,anim: 4 //动画类型
                    });

                    // layer.msg(res.msg,{icon: 2,time:3000});
                }
            }
        });
    });
</script>
<link rel="stylesheet" href="__STATIC__/multiple-select-1.6.0/dist/multiple-select.css">

<!-- Latest compiled and minified JavaScript -->
<script src="__STATIC__/multiple-select-1.6.0/dist/multiple-select.js"></script>
<script>
    $('#channel_id').multipleSelect({
        selectAll:false//是否有全选按钮

    });

    var sceneIdList ="{$channel_id}";


    sceneIdArr = sceneIdList.split(",");


    $('#channel_id option').each(function (i, content) {

        if ($.inArray($.trim(content.value), sceneIdArr) >= 0) {

            this.selected = true;

        }

    });
    //加载完勾选项后也要刷新
    $("#channel_id").multipleSelect('refresh');

</script>
</html>




























